﻿Imports paycircuit.com.google.iap




'''<summary>
'''This is a test class for JWTHeaderObjectTest and is intended
'''to contain all JWTHeaderObjectTest Unit Tests
'''</summary>
<TestClass()> _
Public Class JWTHeaderObjectTest

    Const MY_SELLER_ID As String = "YOUR SELLER ID"
    Const MY_SELLER_SECRET As String = "YOUR SELLER SECRET"
    Const MY_POSTBACK_TYP As String = "google/payments/inapp/item/v1/postback/buy"
    Const THE_ISSUER As String = "Google"

    Private testContextInstance As TestContext

    '''<summary>
    '''Gets or sets the test context which provides
    '''information about and functionality for the current test run.
    '''</summary>
    Public Property TestContext() As TestContext
        Get
            Return testContextInstance
        End Get
        Set(value As TestContext)
            testContextInstance = value
        End Set
    End Property

#Region "Additional test attributes"
    '
    'You can use the following additional attributes as you write your tests:
    '
    'Use ClassInitialize to run code before running the first test in the class
    '<ClassInitialize()>  _
    'Public Shared Sub MyClassInitialize(ByVal testContext As TestContext)
    'End Sub
    '
    'Use ClassCleanup to run code after all tests in a class have run
    '<ClassCleanup()>  _
    'Public Shared Sub MyClassCleanup()
    'End Sub
    '
    'Use TestInitialize to run code before running each test
    '<TestInitialize()>  _
    'Public Sub MyTestInitialize()
    'End Sub
    '
    'Use TestCleanup to run code after each test has run
    '<TestCleanup()>  _
    'Public Sub MyTestCleanup()
    'End Sub
    '
#End Region


    '''<summary>
    '''A test for JWTHeaderObject Constructor
    '''</summary>
    <TestMethod()> _
    Public Sub JWTHeaderObjectConstructorTest()
        Dim algo As JWTHeaderObject.JWTHash = JWTHeaderObject.JWTHash.HS256
        Dim kid As String = "1"
        Dim target As JWTHeaderObject = New JWTHeaderObject(algo, kid)
        Assert.Inconclusive(String.Format("JSON header produced: {0}", JSONHelpers.dataContractToJSON(target)))
    End Sub

    '''<summary>
    '''A test for JWTHeaderObject Constructor
    '''</summary>
    <TestMethod()> _
    Public Sub JWTHeaderObjectConstructorTest1()
        Dim algo As JWTHeaderObject.JWTHash = JWTHeaderObject.JWTHash.HS256
        Dim kid As String = "1"
        Dim typ As String = "JWT"
        Dim target As JWTHeaderObject = New JWTHeaderObject(algo, kid, typ)
        Assert.Inconclusive(String.Format("JSON header produced: {0}", JSONHelpers.dataContractToJSON(target)))
    End Sub

    '''<summary>
    '''A test for JWTHeaderObject Constructor
    '''</summary>
    <TestMethod()>
    Public Sub InvalidJWTHeaderObjectConstructorTest2()
        Dim target As JWTHeaderObject = New JWTHeaderObject() With {.alg = "foo"}
        Assert.Inconclusive(String.Format("INVALID JSON header produced: {0}", JSONHelpers.dataContractToJSON(target)))
    End Sub

    '''<summary>
    '''A test for JWTHeaderObject Constructor
    '''</summary>
    <TestMethod()> _
    Public Sub JWTHeaderObjectConstructorTest3()
        Dim algo As String = "HS256"
        Dim kid As String = "1"
        Dim target As JWTHeaderObject = New JWTHeaderObject(algo, kid)
        Assert.Inconclusive(String.Format("JSON header produced: {0}", JSONHelpers.dataContractToJSON(target)))
    End Sub

    '''<summary>
    '''A test for alg
    '''</summary>
    <TestMethod()> _
    Public Sub algTest()
        Dim target As JWTHeaderObject = New JWTHeaderObject() With {.alg = JWTHeaderObject.JWTHash.HS256.ToString}
        Dim expected As String = "HS256"
        Dim actual As String
        actual = target.alg
        Assert.AreEqual(expected, actual)
    End Sub

    ''' <summary>
    ''' alg in header is required
    ''' </summary>
    ''' <remarks>While you can create an alg with any value, it will fail in verifyJWT</remarks>
    <TestMethod()>
    Public Sub algTestFail()
        Dim badjwtheader As String = "{""typ"":""JWT""}"
        Dim actual As JWTHeaderObject = CType(dataContractJSONToObj(JWTHelpers_Accessor.jwtEncodeB64Url(badjwtheader), New JWTHeaderObject), JWTHeaderObject)
        Assert.IsInstanceOfType(actual, GetType(JWTHeaderObject), "Expected behavior - alg is not set")
    End Sub

    '''<summary>
    '''A test for kid
    '''</summary>
    <TestMethod()> <Ignore()> _
    Public Sub kidTest()
        Dim target As JWTHeaderObject = New JWTHeaderObject() ' TODO: Initialize to an appropriate value
        Dim expected As String = String.Empty ' TODO: Initialize to an appropriate value
        Dim actual As String
        target.kid = expected
        actual = target.kid
        Assert.AreEqual(expected, actual)
        Assert.Inconclusive("Verify the correctness of this test method.")
    End Sub

    '''<summary>
    '''A test for typ
    '''</summary>
    <TestMethod()> _
    Public Sub typTest()
        Dim target As JWTHeaderObject = New JWTHeaderObject() With {.typ = "JWT"}
        Assert.IsTrue(CBool(String.Compare("JWT", target.typ, False) = 0 Or String.Compare("http://openid.net/specs/jwt/1.0", target.typ, False) = 0))
    End Sub
End Class
